//
//  TXP_RadioHotlistTableViewCell.m
//  StayAwhile
//
//  Created by dllo on 16/1/29.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "TXP_RadioHotlistTableViewCell.h"
#import "TXPRadioModel.h"
@interface TXP_RadioHotlistTableViewCell ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic,strong)UICollectionView *myCollectionView;
@end
@implementation TXP_RadioHotlistTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
       
        
        UICollectionViewFlowLayout *myFlowLayout = [[UICollectionViewFlowLayout alloc] init];
        myFlowLayout.itemSize = CGSizeMake(WIDTH/3-10, HEIGHT * 0.15);
        myFlowLayout.minimumInteritemSpacing = 5;
        myFlowLayout.minimumLineSpacing = 5;
        myFlowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
        myFlowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        self.myCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT * 0.15) collectionViewLayout:myFlowLayout];
        self.myCollectionView.delegate = self;
        self.myCollectionView.dataSource = self;
        self.myCollectionView.backgroundColor = [UIColor whiteColor];
        [self.myCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
        [self addSubview:self.myCollectionView];
        
        
    }
    
    return self;
    
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.imgArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    TXPRadioModel *model = self.imgArray[indexPath.item];
    UIImageView *myView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH/3-10, HEIGHT * 0.15)];
    NSURL *url = [NSURL URLWithString:model.coverimg];
    [myView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"c3b08068f41ac81243561c5d387ea55c.jpg"]];
  
    [cell.contentView addSubview:myView];
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    TXPRadioModel *model = self.imgArray[indexPath.item];
    [self.myDelegate pushDetail:model];
}
- (void)setImgArray:(NSMutableArray *)imgArray
{
    _imgArray = imgArray;
    
    [self.myCollectionView reloadData];
}
@end
